package com.digital.herbarium.Util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;

import java.nio.charset.StandardCharsets;

public class SecuretUtil {

//    public final static byte[] KEY = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();

    public  static AES aes = null;

   public static void initAes(){
       String s = "digitalherbarium";

       byte[] KEY = s.getBytes(StandardCharsets.UTF_8);
       aes = SecureUtil.aes(KEY);
   }

    //加密
    public static String encrypt(String content){
        if(aes == null){
            initAes();
        }
        return aes.encryptHex(content);
    }

    //解密

    public  static String decrypt(String content){
        if(aes == null){
            initAes();
        }
        return  aes.decryptStr(content, CharsetUtil.CHARSET_UTF_8);
    }
}
